﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ui="clr-namespace:Bonobo.Irc.Client.UI"
    xmlns:data="clr-namespace:Bonobo.Irc.Client.UI.Data" 
    xmlns:globalization="clr-namespace:System.Globalization;assembly=mscorlib"
    x:Class="Bonobo.Irc.Client.UI.Data.IrcPersonConversationTemplate">

    <DataTemplate x:Key="IrcPersonConversationContentTemplate" >
        <Grid FocusManager.FocusedElement="{Binding ElementName=txtMessage}">
            <Grid.CommandBindings>
                <CommandBinding Command="{x:Static ui:IrcCommands.Send}" 
                                Executed="SendExecuted" />
            </Grid.CommandBindings>
            <Grid.Resources>
                <data:MessageConverter x:Key="MessageConverter" />
                <data:MessageTypeToBrushConverter x:Key="MessageTypeToBrushConverter" />
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="100px" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="27px" />
            </Grid.RowDefinitions>

            <ListBox Name="lvItems"
                     BorderThickness="0"
                     ItemsSource="{Binding Messages}"
                     SelectionMode="Single"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     Grid.Row="0"
                     Grid.Column="0"
                     Grid.ColumnSpan="2"
                     data:SelectorExtenders.IsAutoscroll="true" 
                     IsSynchronizedWithCurrentItem="True"
                     Padding="5">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <DockPanel>
                            <TextBlock Text="{Binding TimeStamp, 
                                                StringFormat={}{0:g},
                                                ConverterCulture={x:Static globalization:CultureInfo.CurrentCulture}}"
                                           Foreground="Gray"
                                           TextWrapping="Wrap"
                                           Margin="0 2px 10px 2px" />
                            <TextBlock TextWrapping="Wrap"
                                           DockPanel.Dock="Right"
                                           Margin="0 2px 0 2px"
                                           Foreground="{Binding Type, Converter={StaticResource MessageTypeToBrushConverter}}"
                                           Text="{Binding Converter={StaticResource MessageConverter}}">
                            </TextBlock>
                        </DockPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <TextBox Margin="2"
                     HorizontalAlignment="Stretch"
                     Grid.Row="2"
                     Grid.Column="0"
                     MaxLength="450"
                     Name="txtMessage">
            </TextBox>
            <Button Margin="2px"
                    Grid.Row="2"
                    Grid.Column="1"
                    Command="{x:Static ui:IrcCommands.Send}"
                    CommandParameter="{Binding}"
                    IsDefault="True">
                _Send
            </Button>

        </Grid>
    </DataTemplate>
</ResourceDictionary>